##=============================================================================
## Appendix: Table 11
##=============================================================================

##-----------------
# clear environment
rm(list=ls())
options(stringsAsFactors = FALSE, scipen = 999)
# source("R/functions.R")

##--------
# Set seed
seed <- sample.int(.Machine$integer.max, 1)
set.seed(seed)

##-------------
# Load Packages
ipak <- function(pkg){new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if(length(new.pkg)) install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}

packages <- c("tidyverse", "texreg", "infer")

ipak(packages)

##---------
# Load Data
#setwd("/Users/austinknuppe/Library/CloudStorage/Dropbox/Ukraine2022WartimeSurvey/Paper_peace/final_version_oct_2024/replication-scripts")
load("clean_ukraine_data.RData")

# Russian language at home
samp1 <- dat %>% 
  filter(home_lang == 2) %>% 
  select(id, frontline_b, ukr_no_nato, compromise_idx_terr, save_lives_z, 
         rus_lang_schools)

samp1 %>%
  t_test(formula = compromise_idx_terr  ~ frontline_b, 
         alternative = "two-sided", order = c(0,1))

samp1 %>%
  t_test(formula = save_lives_z  ~ frontline_b, 
         alternative = "two-sided", order = c(0,1))

samp1 %>%
  t_test(formula = ukr_no_nato  ~ frontline_b, 
         alternative = "two-sided", order = c(0,1))

samp1 %>%
  t_test(formula = rus_lang_schools  ~ frontline_b, 
         alternative = "two-sided", order = c(0,1))


# Russian, both, hard to say
samp2 <- dat %>% 
  select(id, frontline_b, ukr_no_nato, compromise_idx_terr, save_lives_z, 
         rus_lang_schools, home_lang) %>% 
  filter(home_lang == 2 | home_lang == 3 | home_lang == 7)

samp2 %>%
  t_test(formula = compromise_idx_terr  ~ frontline_b, 
         alternative = "two-sided", order = c(0,1))

samp2 %>%
  t_test(formula = save_lives_z  ~ frontline_b, 
         alternative = "two-sided", order = c(0,1))

samp2 %>%
  t_test(formula = ukr_no_nato  ~ frontline_b, 
         alternative = "two-sided", order = c(0,1))

samp2 %>%
  t_test(formula = rus_lang_schools  ~ frontline_b, 
         alternative = "two-sided", order = c(0,1))


# Ethnic Russian respondents only
samp3 <- dat %>% 
  select(id, frontline_b, ukr_no_nato, compromise_idx_terr, save_lives_z, 
         rus_lang_schools, ethnic) %>% 
  filter(ethnic == 2)

samp3 %>%
  t_test(formula = compromise_idx_terr  ~ frontline_b, 
         alternative = "two-sided", order = c(0,1))

samp3 %>%
  t_test(formula = save_lives_z  ~ frontline_b, 
         alternative = "two-sided", order = c(0,1))

samp3 %>%
  t_test(formula = ukr_no_nato  ~ frontline_b, 
         alternative = "two-sided", order = c(0,1))

samp3 %>%
  t_test(formula = rus_lang_schools  ~ frontline_b, 
         alternative = "two-sided", order = c(0,1))

rm(list = ls())
##=============================================================================
## End of File
##=============================================================================